<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t("待办任务") }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('待办标题')" prop="title">
        <el-input
          v-model="queryParams.title"
          :placeholder="$t('待办标题')"
          size="small"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('申请人')" prop="applyUserId">
        <UserSelect
          v-model="queryParams.applyUserId"
          size="small"
          :placeholder="$t('选择用户')"
        />
      </el-form-item>
      <el-form-item :label="$t('流程名称')" prop="processName">
        <el-input
          v-model="queryParams.processName"
          size="small"
          :placeholder="$t('流程名称')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      tooltip-effect="darkTable"
      :data="todoList"
      border
    >
      <el-table-column :label="$t('待办标题')" align="left" prop="title" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <i v-show="scope.row.urgent === 'Y'" class="urgent" />
          <span v-show="scope.row.readStatus" class="no" />
          <el-link type="primary" @click="openTask(scope.row)">{{ scope.row.title }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="applyNickName" width="100" />
      <el-table-column :label="$t('申请时间')" align="center" prop="startTime" class-name="small-padding fixed-width" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('当前环节')" align="center" prop="taskName" class-name="small-padding fixed-width" width="130">
        <template slot-scope="scope">
          <span>{{ $t(scope.row.taskName) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('流程名称')" align="center" prop="processName" class-name="small-padding fixed-width" width="130">
        <template slot-scope="scope">
          <span>{{ $t(scope.row.processName) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog v-if="formOpen" :visible.sync="formOpen" width="95%" custom-class="maxDialog actTaskDialog" :close-on-click-modal="false" :lock-scroll="false">
      <ActTaskForm ref="actTaskForm" />
    </el-dialog>

  </div>
</template>

<script>
import { todoList } from '@/api/act/task/actTask'
  import ActTaskForm from './actTaskForm'
export default {
  components: {
    ActTaskForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 待办表格数据
      todoList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        applyUserId: '',
        processName: undefined
      },
      wfMenuProcessData: {},
      // 表单参数
      form: {}
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    this.$bus.$emit('async_done')
  },
  methods: {
    /** 查询待办列表 */
    getList() {
      this.loading = true
      todoList(this.queryParams).then(response => {
        this.todoList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.formOpen = false
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 打开待办页面
    openTask(row) {
      this.formOpen = true
      row.readStatus = false
      this.$nextTick(() => {
        this.$refs.actTaskForm.init(row)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
/deep/.actTaskDialog{
  .el-dialog__body{
    height: 100%;
    padding: 0px!important;
    .acttask, .row, .col{
      height: 100%;
    }
    .acttask{
      padding: 20px!important;
    }
  }
  .el-form-disabled{
    .el-row {
      .el-col{
        .el-form-item{
          &:after{
            width: 200px;
          }
          .el-form-item__label{
            width: 200px !important;
          }
        }
      }
    }
  }
}
</style>
